package Pokero;

import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JTextPane;

public class BetFrame extends JFrame implements ActionListener{

	 private JCheckBox box1;
     private JCheckBox box2;
     private JCheckBox box3;
     private JCheckBox box4;
     private JFrame frame;
     private JButton apply; 
     private JTextPane text;
     private int Selected = 0;
     private int HumAmount = 0;
     
     public BetFrame(int HumAmount) {
         
         //okno
         super("Wymiana");
         frame = new JFrame();
         setVisible(true);
         setSize(400,200);
         setLayout(new FlowLayout());
         setLocationRelativeTo(null);
         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         

         //text
         Font f = new Font(Font.SANS_SERIF, 5, 17);
         text = new JTextPane();
         text.setVisible(true);
         text.setText("Zaznacz pole z nazwa gracza, jezeli przystepujesz do licytacji.");               
         text.setEditable(false);
         text.setBackground(null);
         text.setFont(f);
         
         add(text);
         
         
         //check boxy
         box1 = new JCheckBox("1");
         box2 = new JCheckBox("2");
         box3 = new JCheckBox("3");
         box4 = new JCheckBox("4");
         
         /*box1.addItemListener(this);
         box2.addItemListener(this);
         box3.addItemListener(this);
         box4.addItemListener(this);*/
                         
         add(box1);
         add(box2);
         add(box3);
         add(box4);
         
         if(HumAmount < 2) {
        	 box2.setVisible(false);
             box3.setVisible(false);
             box4.setVisible(false);
         }
         if(HumAmount < 3) {     
             box3.setVisible(false);
             box4.setVisible(false);
         }
         if(HumAmount < 4) {
             box4.setVisible(false);
         }
         this.HumAmount = HumAmount;
         
         apply = new JButton("Zatwierdz");
         
         apply.addActionListener(this);
         
         add(apply);
         
       //blokada rozmiaru okna
         this.addComponentListener(new ComponentAdapter(){
     public void componentResized(ComponentEvent e){
         Dimension d=BetFrame.this.getSize();
         if(d.width != 400)
             d.width=400;
         if(d.height != 200)
             d.height=200;
         BetFrame.this.setSize(d);
     }
 });
     }
	
	
	
	@Override
	public void actionPerformed(ActionEvent e) {
		
		Object source = e.getSource();
		
		if(source == apply) {
			if(box1.isSelected()) {
				AuctionFrame.account[0] = 5;
				PokerFrame.pula +=5;
				PokerFrame.bpula.setText("Pula: " + PokerFrame.pula);
			}
            
			if(box2.isSelected()) {
            	AuctionFrame.account[1] = 5;
            	PokerFrame.pula +=5;
				PokerFrame.bpula.setText("Pula: " + PokerFrame.pula);
			}
          
            
            if(box3.isSelected()) {
            	AuctionFrame.account[2] = 5;
            	PokerFrame.pula +=5;
				PokerFrame.bpula.setText("Pula: " + PokerFrame.pula);
            }
           
            
            if(box4.isSelected()) { 
            	AuctionFrame.account[3] = 5;
            	PokerFrame.pula +=5;
				PokerFrame.bpula.setText("Pula: " + PokerFrame.pula);
            }
            
            new AuctionFrame(HumAmount);
            dispose();
		}
		
	}


}
